/**
 * Created by ASUS on 2018/1/4.
 */
function initFilter(){
// 方法默认去为排序按钮和侧滑出的筛选标签添加对应的点击事件
    var fliterItemBoxLabels = $(".fliterItemBoxLabel");
    var filterItems = $(".filterItem");
    var labelCodeBoxs = $(".labelCodeBox");
    filterItems.on("tap",function(){
        if(filterObjValue==undefined){filterObjValue = {};};
        if(filterObjValue.orderWay==undefined){
            filterObjValue.orderWay = 0
        }
        if(!$(this).hasClass("curFilter")){
            $(this).addClass("curFilter").parent().siblings().find(".filterItem").removeClass("curFilter");
            //filterObjValue.orderWay = 0
        }else{
            if($(this).parent().index()==2){
                filterObjValue.orderWay = filterObjValue.orderWay==0?1:0;
                if(filterObjValue.orderWay==0){
                    $(".orderWayUp").show();
                    $(".orderWayDown").hide();
                }else{
                    $(".orderWayUp").hide();
                    $(".orderWayDown").show();
                }


            }

        };
        filterObjValue.type = $(this).parent().index();

//        样式更改



//      更新完type参数后及时请求并且更新vue对象中的数组
//      请求之前先还原分页计数
        paginationArr[0] = 1;
        requestData({
            tabNum:0,
            success:function(msg) {
                vueObjArr[0].datas = [];
                msg.obj.map(function(ele,index){
                    vueObjArr[0].datas.push(ele);
                });
                //数据加完之后删除loading动画
                $(vueObjArr[0].boxName).find(".mui-loading").remove();
            }
        });
    });

    fliterItemBoxLabels.on("tap",function(){
        if($(this).hasClass("fliterItemBoxLabelCur")){return;};
        $(this).addClass("fliterItemBoxLabelCur").parent().siblings().find(".fliterItemBoxLabel").removeClass("fliterItemBoxLabelCur");
        if(filterObjValue == undefined){
            filterObjValue = {};
        }
        $(".filterMainItemBox").each(function(){
            if(filterObjValue[$(this).attr("id")]==undefined){
                filterObjValue[$(this).attr("id")]={};
            }
        })


        var rootName = $(this).parents(".filterMainItemBox").attr("id");
        var name;
        if(rootName=="areaId"){
            name = "areaId";
        }else{
            name = $(this).parents(".labelCodeBox").attr("labelCode");
        }
        filterObjValue[rootName][name] = $(this).parent().attr("labelCode");
    });
    $("#filterMenuFinish").on("tap",function(){
        if(filterObjValue == undefined){return;};
//      请求之前先还原分页计数
        paginationArr[0] = 1;
        requestData({
            tabNum:0,
            success:function(msg) {
                vueObjArr[0].datas = [];
                msg.obj.map(function(ele,index){
                    vueObjArr[0].datas.push(ele);
                });
                //数据加完之后删除loading动画
                $(vueObjArr[0].boxName).find(".mui-loading").remove();
            }
        });
        mui('.mui-off-canvas-wrap').offCanvas().close();
    });

    $("#filterMenuReset").on("tap",function(){
        if(filterObjValue == undefined){return;};
        for(var i in filterObjValue){
            for(var j in filterObjValue[i]){
                filterObjValue[i][j] = "";
            }
        }
        $("#eCode").find("input").val("");
        fliterItemBoxLabels.removeClass("fliterItemBoxLabelCur");
    });


//    需要监听input输入  初始化一个简单的vue对象
    var vueObj = new Vue({
        el:"#eCode",
        data:{
            minPrice:"",
            maxPrice:""
        },
        directives:{
            keyup:{
                componentUpdated:function(el){
                    if(filterObjValue==undefined){
                        filterObjValue = {};
                        if(filterObjValue.eCode==undefined){
                            filterObjValue.eCode = {};
                        }
                    }
                    filterObjValue.eCode["minPrice"] = vueObj.minPrice;
                    filterObjValue.eCode["maxPrice"] = vueObj.maxPrice;
                }
            }
        }
    })
}